using UnityEngine;

public class JoystickButtonController : MonoBehaviour
{
	public enum buttonDirection
	{
		Forward = 0,
		Back = 1,
		Left = 2,
		Right = 3,
		Stop = 4,
		CamLeft = 5,
		CamRight = 6,
		HandBrake = 7,
		Boost = 8,
		Jump = 9
	}

	public buttonDirection butDirection;

	private void OnDragOver(GameObject draggedObject)
	{
		EventClick(1f);
	}

	private void OnDragOut(GameObject draggedObject)
	{
		EventClick(0f);
	}

	private void OnDrop(GameObject draggedObject)
	{
		EventClick(0f);
	}

	private void OnPress(bool isDown)
	{
		if (isDown)
		{
			EventClick(1f);
		}
		else
		{
			EventClick(0f);
		}
	}

	private void OnDisable()
	{
		if (CameraZoneEnabler.instance != null)
		{
			EventClick(0f);
		}
	}

	private void EventClick(float value)
	{
		switch (butDirection)
		{
		case buttonDirection.Back:
			CameraZoneEnabler.GetCameraZone().OnPress(false);
			BasicInput.Back = value;
			if (CameraControl.instance != null && CameraControl.instance.enabled)
			{
				CameraControl.instance.yInputAxis = value * -1f;
			}
			break;
		case buttonDirection.Forward:
			CameraZoneEnabler.GetCameraZone().OnPress(false);
			BasicInput.Forward = value;
			break;
		case buttonDirection.Left:
			BasicInput.LeftRight = value * -1f;
			break;
		case buttonDirection.Right:
			BasicInput.LeftRight = value;
			break;
		case buttonDirection.Stop:
			CameraZoneEnabler.GetCameraZone().OnPress(false);
			BasicInput.HandBrake = value;
			break;
		case buttonDirection.CamLeft:
			if (CameraControl.instance != null)
			{
				CameraZoneEnabler.GetCameraZone().OnPress(false);
				CameraControl.instance.xInputAxis = value * -1f;
			}
			break;
		case buttonDirection.CamRight:
			if (CameraControl.instance != null)
			{
				CameraZoneEnabler.GetCameraZone().OnPress(false);
				CameraControl.instance.xInputAxis = value;
			}
			break;
		case buttonDirection.HandBrake:
			CameraZoneEnabler.GetCameraZone().OnPress(false);
			BasicInput.HandBrake = value;
			break;
		case buttonDirection.Boost:
			CameraZoneEnabler.GetCameraZone().OnPress(false);
			BasicInput.Boost = value;
			break;
		case buttonDirection.Jump:
			CameraZoneEnabler.GetCameraZone().OnPress(false);
			BasicInput.carJump = value;
			break;
		}
	}
}
